https://leetcode.cn/problems/sum-lists-lcci/description/

面试题 02.05. 链表求和

class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        ListNode*head=new ListNode(-1);
        ListNode*cur=head;
        int carry=0,sum=0;
        while(l1||l2||carry)
        {
            sum=0;
            if(l1)
            {
                sum+=l1->val;
                l1=l1->next;
            }
            if(l2)
            {
                sum+=l2->val;
                l2=l2->next;
            }

            sum+=carry;
            ListNode* next=new ListNode(sum%10);
            carry=sum/10;
            cur->next=next;
            cur=cur->next;
        }
        return head->next;
    }
};